package com.example.demo2.controller;

import com.example.demo2.dao.Student;
import com.example.demo2.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    @ResponseBody
    public String students() {
        return studentService.findAllStudent().toString();
    }

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public int insertStudent(Student student) {
        return studentService.insertStudent(student);
    }

    @RequestMapping(method = RequestMethod.PUT)
    @ResponseBody
    public int updateStudent(Student student) {
        return studentService.updateStudent(student);
    }

    @RequestMapping(value = "{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public int deleteStudent(@PathVariable(value = "id") int id) {
        return studentService.deleteStudent(id);
    }
}
